import request from '@/utils/request'


// 查询退住列表
export function listCheckout(query) {
  return request({
    url: '/check/checkout/list',
    method: 'get',
    params: query
  })
}

// 查询退住详细
export function getCheckout(id) {
  return request({
    url: '/check/checkout/' + id,
    method: 'get'
  })
}

// 新增退住
export function addCheckout(data) {
  return request({
    url: '/check/checkout',
    method: 'post',
    data: data
  })
}

// 修改退住
export function updateCheckout(data) {
  return request({
    url: '/check/checkout',
    method: 'put',
    data: data
  })
}

// 删除退住
export function delCheckout(id) {
  return request({
    url: '/check/checkout/' + id,
    method: 'delete'
  })
}

export function checkOutDto(id){
  return request({
    url: '/check/checkout/getCheckOutDto/' + id,
    method: 'get'
  })
}

export function addCheckOutBill(data){
  return request({
    url: '/check/checkout/addBill',
    method: 'post',
    data: data
  })
}
export function getActivityUser(id){
  return request({
    url: '/check/checkout/getActivityUser/'+id,
    method: 'get'
  })
}
export function approval(data){
  return request({
    url: '/check/checkout/approval',
    method: 'post',
    params: data
  })
}
export function removeContract(data){
  return request({
    url: '/check/checkout/removeContract',
    method: 'post',
    params: data
  })
}
// 上传退款凭证（单图片）
export function uploadRefundVoucher(data) {
  const formData = new FormData();
  formData.append("id", data.id);
  formData.append("refundWay", data.refundWay);
  formData.append("refundRemark", data.refundRemark || "");
  formData.append("refundAmount", data.refundAmount);

  // 只取第一个文件（单图上传）
  if (Array.isArray(data.refundVoucher) && data.refundVoucher.length > 0) {
    formData.append("refundVoucher", data.refundVoucher[0].raw);
  } else if (data.refundVoucher && data.refundVoucher.raw) {
    formData.append("refundVoucher", data.refundVoucher.raw);
  } else {
    console.warn("未选择退款凭证图片");
  }
 console.log(formData.get("refundAmount"))
  return request({
    url: "/check/checkout/uploadRefundVoucher",
    method: "post",
    data: formData,
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
}
export function getActivityLog(id){
  return request({
    url: '/check/checkout/getActivityLog/'+id,
    method: 'get'
  })
}
export function getCheckoutId(processInstanceId){
  return request({
    url: '/check/checkout/getCheckoutId',
    method: 'get',
    params: {processInstanceId}
  })
}



